﻿using UnityEngine;

public class RewardedVideoButton : MonoBehaviour
{
    private const string ACTION_NAME = "rewarded_video";

    private void OnEnable()
    {
        Timer.Schedule(this, 0.1f, AddEvents);
    }

    private void AddEvents()
    {

         HandleRewardBasedVideoRewarded();

    }

    public void OnClick()
    {
        //if (IsAvailableToShow())
        //{
        //    //AdmobController.instance.ShowRewardBasedVideo();
        //}
        //else if (!IsActionAvailable())
        //{
            int remainTime = (int)(GameConfig.instance.rewardedVideoPeriod - CUtils.GetActionDeltaTime(ACTION_NAME));
            Toast.instance.ShowMessage("Please wait " + remainTime + " seconds for the next ad");
        //}
        //else
        //{
        //    Toast.instance.ShowMessage("Ad is not available now, please wait..");
        //}

        Sound.instance.PlayButton();
    }

    public void HandleRewardBasedVideoRewarded()
    {
        
    }

    public bool IsAvailableToShow()
    {
        return IsActionAvailable() && IsAdAvailable();
    }

    private bool IsActionAvailable()
    {
        return CUtils.IsActionAvailable(ACTION_NAME, GameConfig.instance.rewardedVideoPeriod);
    }

    private bool IsAdAvailable()
    {
        //if (AdmobController.instance.rewardBasedVideo == null) return false;
        //bool isLoaded = AdmobController.instance.rewardBasedVideo.IsLoaded();
        return true;
    }

    private void OnDisable()
    {

    }
}
